package io.terminus.spzx.manager.config;

import org.springframework.stereotype.Component;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @Author lichunlong lcl253137@alibaba-inc.com
 * @Desc 允许跨域访问的全局配置类
 * @Date 2024-03-25
 */
@Component
public class CorsWebMvcConfigurer implements WebMvcConfigurer {

    @Override
    public void addCorsMappings(CorsRegistry registry) {
        /*
         * 1、addMapping: 添加路径规则
         * 2、allowCredentials: 是否允许在跨域的情况下传递Cookie
         * 3、allowedOriginPatterns: 允许请求来源的域规则
         * 4、allowedHeaders: 允许所有的请求头
         */
        registry.addMapping("/**")
                .allowCredentials(true)
                .allowedOriginPatterns("*")
                .allowedMethods("*")
                .allowedHeaders("*");
    }
}
